﻿using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.DtoModel.Sys;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Sys;

namespace VisionCloud.Api.Controllers.Sys
{
    /// <summary>
    /// 角色控制器
    /// </summary>
    [SystemModuleAttribute("角色控制器")]
    [ApiAuthorize(PolicyEnum.RequireRolePermission)]
    [ApiVersion("1.0")]
    [Route("api/sys/[controller]/[Action]")]
    [ApiExplorerSettings(GroupName = "角色控制器")]
    public class RoleController : ApiBaseController
    {
        /// <summary>
        /// 角色服务
        /// </summary>
        public RoleService RoleService { get; set; }

        #region 角色

        /// <summary>
        /// 创建角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> CreateRole(SysRoleDto model)
        {
            return await TryCatchAsync(RoleService.CreateRole(model, TokenModel.YunUserGuid));
        }

        /// <summary>
        /// 编辑角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> EditRole(SysRoleDto model)
        {
            return await TryCatchAsync(RoleService.UpdateRole(model, TokenModel.YunUserGuid));
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> DeleteRole(SysRoleDto model)
        {
            return await TryCatchAsync(RoleService.DeleteRole(model.RoleId, TokenModel.YunUserGuid));
        }

        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> GetRoleList(SysRoleCondition condition)
        {
            return await TryCatchAsync(RoleService.GetPage(condition));
        }

        #endregion 角色
    }
}